from sqlalchemy import Boolean, Column, Integer, String, ForeignKey,BigInteger, false
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func
from models import Base
from uuid import uuid4
from .user import User
from sqlalchemy_serializer import SerializerMixin
from sqlalchemy import TIMESTAMP

def generate_id():
    return str(uuid4().hex)


class Address(Base,SerializerMixin):
    __tablename__ = 'address'
    id = Column(String(200), primary_key=True,default=generate_id,autoincrement=False)
    serialize_only=['id','realname','mobile','region','detail']
    realname = Column(String(255))
    mobile = Column(String(255))
    region = Column(String(255))
    detail = Column(String(255))
    create_time = Column(TIMESTAMP, server_default=func.now())
    update_time = Column(TIMESTAMP, server_default=func.now(), onupdate=func.now())
    is_default = Column(Boolean, default=False)
    
    user_id = Column(BigInteger, ForeignKey('user.id'))
    user=relationship(User,backref='address')